﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using ERPStore.Extensions;

namespace ERPStore.Cart.Repositories
{
	/// <summary>
	/// Pour les tests
	/// </summary>
	public class MockCartRepository : ERPStore.Cart.Repositories.ICartRepository
	{
		private List<ERPStore.Cart.Repositories.Datas.Cart> m_List;

		public MockCartRepository()
		{
			m_List = new List<ERPStore.Cart.Repositories.Datas.Cart>();
		}

		public IQueryable<Datas.Cart> GetCartList()
		{
			return m_List.AsQueryable();
		}

		public void Save(ERPStore.Models.OrderCart cart)
		{
			var existing = m_List.SingleOrDefault(i => i.Code == cart.Code);
			if (existing != null)
			{
				var index = m_List.IndexOf(existing);
				existing = cart.ToCartData();
				m_List[index] = existing;
			}
			else
			{
				var data = cart.ToCartData();
				data.Id = m_List.Count + 1;
				cart.Id = data.Id;
				m_List.Add(data);
			}
		}

		public void Remove(string cartId)
		{
			var existing = m_List.SingleOrDefault(i => i.Code == cartId);
			if (existing != null)
			{
				m_List.Remove(existing);
			}
		}

		public IList<ERPStore.Models.CartItem> GetLastCartItem(int itemCount)
		{
			return null;
		}
	}
}
